<template>
  <el-dialog
    title="详情"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="身份证正反面">
	    <img id="idCardFront" style="width: 300px;height: 200px" :src="idCardFrontUrl"></img>
        <img id="idCardBack" style="width: 300px;height: 200px" :src="idCardBackUrl"></img>
      </el-form-item>

      <el-form-item label="驾驶证正反面" :class="{ 'is-required': !dataForm.id }">
        <img id="driverLicenseFront" style="width: 300px;height: 200px" :src="driverLicenseFrontUrl"></img>
        <img id="driverLicenseBack" style="width: 300px;height: 200px" :src="driverLicenseBackUrl"></img>
      </el-form-item>

      <el-form-item label="行驶证正面">
        <img id="drivingLicenseFront" style="width: 300px;height: 200px" :src="drivingLicenseFrontUrl"></img>
        <img id="drivingLicenseBack" style="width: 300px;height: 200px" :src="drivingLicenseBackUrl"></img>
      </el-form-item>

      <el-form-item label="人车合影" size="mini">
        <div v-for="(item,index) in groupPhotoUrl" :key="index">
          <img id="groupPhoto" :src="item" style="width: 300px;height: 200px"/>
        </div>
      </el-form-item>

      <el-form-item label="审核状态" size="mini" prop="auditState" @change="auditStateChange">
        <el-radio-group v-model="dataForm.auditState">
          <el-radio :label="2">驳回</el-radio>
          <el-radio :label="3">通过</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="审核备注" prop="remark">
        <el-input v-model="dataForm.remark" placeholder="审核备注"></el-input>
      </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { } from '@/utils/validate'
  export default {
    data () {
      return {
        visible: false,
        idCardFrontUrl: '1',
        idCardBackUrl: '2',
        driverLicenseFrontUrl: '3',
        driverLicenseBackUrl: '4',
        drivingLicenseFrontUrl: '5',
        drivingLicenseBackUrl: '6',
        groupPhotoUrl:[],
        roleList: [],
        dataForm: {
          id: 0,
          remark: '通过',
          auditState: 3

        },
        dataRule: {
          remark: [
            { required: true, message: '用户名不能为空', trigger: 'blur' }
          ],
          auditState: [
            { required: true, message: '审核状态不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        console.log("78-id:"+this.dataForm.id)
        this.$http({
          url: this.$http.adornUrl('/sys/role/select'),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          this.roleList = data && data.code === 0 ? data.list : []
        }).then(() => {
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
          })
        }).then(() => {
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/cuser/auditDetailByUserId`),
              method: 'get',
              params: this.$http.adornParams({
                'userId': this.dataForm.id || undefined
              }),
              data: this.$http.adornData({
                'userId': this.dataForm.id || undefined
              })
              // params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                var t = data.data;
                  this.idCardFrontUrl = t.idCardFront
                  this.idCardBackUrl = t.idCardBack
                  this.driverLicenseFrontUrl = t.driverLicenseFront
                  this.driverLicenseBackUrl = t.driverLicenseBack
                  this.drivingLicenseFrontUrl = t.drivingLicenseFront
                  this.drivingLicenseBackUrl = t.drivingLicenseBack
                 var arr = t.groupPhoto.split(";");
                  this.groupPhotoUrl=arr;
                  // arr.some((v,i)=>{
                  //     $("#groupPhoto").append(" <img id=\"drivingLicenseFront\" style=\"width: 300px;height: 200px\" :src=\""+v+"\"></img>");
                  // });


              }
            })
          }
        })
      },
      auditStateChange(){
        this.dataForm.remark = ''
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/cuser/saveAudit`),
              method: 'post',
              params: this.$http.adornParams({
                'userId': this.dataForm.id || undefined,
                'remark': this.dataForm.remark,
                'auditState': this.dataForm.auditState
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
